﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UIapp
{
    public partial class frmMain : Form
    {
        #region Campos
        Interfaces.IPantalla pantallaActual = null;
        #endregion

        #region Tratamiento de eventos

        private void btnNuevo_Click(object sender, EventArgs e)
        {
            this.pantallaActual.Nuevo();
        }

        private void btnModificar_Click(object sender, EventArgs e)
        {
            this.pantallaActual.Editar();
        }

        private void btnEliminar_Click(object sender, EventArgs e)
        {
            this.pantallaActual.Eliminar();
        }

        private void btnRefrescar_Click(object sender, EventArgs e)
        {
            this.pantallaActual.Refrescar();
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            this.pantallaActual.Buscar();
        }

        private void radDock1_ActiveWindowChanging(object sender, Telerik.WinControls.UI.Docking.DockWindowCancelEventArgs e)
        {

            if (e.NewWindow is Telerik.WinControls.UI.Docking.HostWindow)
            {
                this.pantallaActual = (Interfaces.IPantalla)(e.NewWindow as Telerik.WinControls.UI.Docking.HostWindow).MdiChild;
                this.MostrarComandosSoportados(this.pantallaActual.ComandosSoportados);
            }
            else
            {  
                this.MostrarComandosSoportados(0);
                this.pantallaActual = null;
            }
               

        }

        private void radDock1_DockStateChanging_1(object sender, Telerik.WinControls.UI.Docking.DockStateChangingEventArgs e)
        {

            if (e.NewWindow is Telerik.WinControls.UI.Docking.HostWindow)
            {
                this.pantallaActual = (Interfaces.IPantalla)(e.NewWindow as Telerik.WinControls.UI.Docking.HostWindow).MdiChild;
                this.MostrarComandosSoportados(this.pantallaActual.ComandosSoportados);
            }
            else
            {
                this.MostrarComandosSoportados(0);
                this.pantallaActual = null;
            }
        }

        #endregion

        #region Metodos Auxiliares
        private void MostrarComandosSoportados(int comandos)
        {
            if ((comandos & (int)Interfaces.ComandosPantalla.Nuevo) > 0)
                this.btnNuevo.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            else
                this.btnNuevo.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;

            if ((comandos & (int)Interfaces.ComandosPantalla.Editar) > 0)
                this.btnModificar.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            else
                this.btnModificar.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;

            if ((comandos & (int)Interfaces.ComandosPantalla.Eliminar) > 0)
                this.btnEliminar.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            else
                this.btnEliminar.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;

            if ((comandos & (int)Interfaces.ComandosPantalla.Refrescar) > 0)
                this.btnRefrescar.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            else
                this.btnRefrescar.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;

            if ((comandos & (int)Interfaces.ComandosPantalla.Buscar) > 0)
                this.btnBuscar.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            else
                this.btnBuscar.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;

            if (comandos == 0)
                this.pantallaActual = null;
        }
        #endregion

        public frmMain()
        {
            InitializeComponent();
            Comun.frmMainSize = this.Size;
            Comun.frmMainLocation = this.Location;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Views.frmBancos b = new Views.frmBancos();
            b.MdiParent = this;
            b.Show();
        }
               
        private void button2_Click(object sender, EventArgs e)
        {
            //Views.frmCiudades b = new Views.frmCiudades();
            //b.MdiParent = this;
            //b.Show();

            Comun.ShowLoadingFRM();
        }

        private void frmMain_SizeChanged(object sender, EventArgs e)
        {
             Comun.frmMainSize = this.Size;
        }

        private void frmMain_LocationChanged(object sender, EventArgs e)
        {
            Comun.frmMainLocation = this.Location;
        }  
    }
}
